package com.fhao.forum.controller;

import com.fhao.forum.common.AppResult;
import com.fhao.forum.exception.ApplicationException;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiResponses
@RestController//表示返回的结果是数据.
@RequestMapping("/test")//定义一级映射路径
public class TestController {
    @ApiResponse(description = "测试接口1,显示你好Spring boot")
    @GetMapping("/hello")
    public String hello() {
        return "hello,Spring boot";
    }

    @ApiResponse(description = "测试接口2,显示这是一个Exception")
    @GetMapping("/exception")
    public AppResult exception() throws Exception {
        throw new Exception("这是一个Exception");
    }

    @ApiResponse(description = "测试接口3,显示这是一个自定义异常", responseCode = "1")
    @GetMapping("/appException")
    public AppResult applicationException() {
        throw new ApplicationException("这是一个自定义异常");
    }

    @ApiResponse(description = "测试接口4,传入信息姓名,显示你好信息")
    @PostMapping("/helloByName")
    public String helloByName(String name) {
        return "hello : " + name;
    }
}
